#define _CRT_SECURE_NO_WARNINGS 1
typedef struct ListNode ListNode;
struct ListNode* removeElements(struct ListNode* head, int val) {
    ListNode* newHead, * newTail;
    newHead = newTail = NULL;
    ListNode* pcur = head;
    while (pcur)
    {
        if (pcur->val != val)
        {
            if (newHead == NULL)
            {
                newHead = pcur;
                newTail = pcur;
            }
            else {
                newTail->next = pcur;
                newTail = newTail->next;
            }
        }
        pcur = pcur->next;
    }
    if (newTail)
        newTail->next = NULL;
    return newHead;
}